package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan string)
	ch2 := make(chan string)
	go Producer(ch)
	go Producer2(ch2)
	go Consumer(ch, ch2)
	time.Sleep(10 * time.Second)
}

func Producer(ch chan string) {
	for i := 0; i < 10; i++ {
		ch <- fmt.Sprintf("Hello_%d", i)	//往通道中写数据
		time.Sleep(200 * time.Millisecond)
	}
}

func Producer2(ch chan string) {
	for i := 0; i < 10; i++ {
		ch <- fmt.Sprintf("World_%d", i) //往通道中写数据
		time.Sleep(1 * time.Second)
	}
}

func Consumer(ch, ch2 chan string) {
	for true {
		select {
		case d := <- ch:
			fmt.Printf("get data from channel_1, data=%s\n", d)
		case d2 := <-ch2:
			fmt.Printf("get data from channel_2, data=%s\n", d2)
		}
	}
}